import os
import sys



def bin_to_string(bin_buf):
    
    string_buf = "{"
    for x in bin_buf:
        string_buf = string_buf + hex(x)+','
        #print(hex(x))
    string_buf = string_buf + '}'
    return string_buf

def bin_to_string_format(bin_buf):
    
    string_buf = "{"
    row = 0
    for x in bin_buf:
        dat = hex(x)
        string_buf = string_buf + dat + ','

        
        if(row%16 == 15):
            string_buf = string_buf + '\n'
        row = row+1
        


        
    string_buf = string_buf + '}\n'
    return string_buf

all_tring  = ""



for rt, dirs, files in os.walk("."):
    for f in files:
        fname = os.path.splitext(f)

        if fname[1].lower() == '.bin':

            fd = open(f,"rb+")
            buf = fd.read()
            fd.close()
            #s = bin_to_string(buf)
            s = bin_to_string_format(buf)
            all_tring = all_tring + "," + s
            fw = open(fname[0]+".txt","wb+")
            print(fw)
            fw.write(s.encode(encoding = "utf-8"))
            fw.close()
            #print(s)


fw = open("all_tring.txt","w+")
fw.write(all_tring)
fw.close()


            #print(f)
            #print(fname)
            
        #new = fname[0] + 'b' + fname[1]
        #os.rename(os.path.join(rt,f),os.path.join(rt,new))


'''
string_buf = "{"
for x in buf:
    string_buf = string_buf + hex(x)+','
    #print(hex(x))

string_buf = string_buf + '}'
'''



